package com.shr.code_interview;

public class Solution_22 {
    public static ListNode FindKthToTail(ListNode head,int k) {
        if(head == null)
        	return null ;
        ListNode front = head;
        for(int i = 0;i<k-1;i++){
        	if(front.next != null)
        		front = front.next ;
        	else return null ;
        }
        
        ListNode follow = head ;
        while(front.next != null){
        	front = front.next;
        	follow = follow.next ;
        }
        return follow ;
    }	
    public static void main(String[] args) {
		ListNode head = new ListNode(0) ;
		ListNode node = head;
    	for(int i = 1; i<5; i++){
    		node.next = new ListNode(i);
    		node = node.next ;
		}
    	System.out.println(FindKthToTail(head, 0).val);
	}
}


class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}